package com.summary.controller;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.summary.domain.TbSummary;
import com.summary.domain.dto.TbSummaryDto;
import com.summary.service.ITbSummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname DailyController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2023/12/15 10:37
 * @Created by m元波
 */
@RestController
@RequestMapping("/summary")
public class DailyController extends BaseController {
    @Autowired
    private ITbSummaryService tbSummaryService;

    /**
     * 管理端动态查询记录
     * @return
     */
    @PreAuthorize("@ss.hasPermi('summary:summary:list')")
    @GetMapping("/list")
    public TableDataInfo list( TbSummary tbSummary, PageDomain pageDomain)
    {
        PageHelper.startPage(pageDomain.getPageNum(),pageDomain.getPageSize());
        List<TbSummary> list = tbSummaryService.selectTbSummaryListByPage(tbSummary);
        return getDataTable(list);
    }


    @Log(title = "日报业务", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody TbSummaryDto summaryDto) {
        return tbSummaryService.saveDaily(summaryDto);
    }
    @Log(title = "日报业务", businessType = BusinessType.INSERT)
    @PostMapping("update")
    public
    AjaxResult update(@RequestBody TbSummaryDto tbSummaryDto){
        return tbSummaryService.update(tbSummaryDto);
    }



    @Log(title = "保存等级信息业务", businessType = BusinessType.UPDATE)
    @PostMapping("/save-level")
    public AjaxResult saveLevel(@RequestBody TbSummaryDto summaryDto) {
        return tbSummaryService.saveLevel(summaryDto);
    }

    /**
     * 查询月报业务列表
     */
    @GetMapping("/month-summary")
    public AjaxResult monthSummary(TbSummaryDto summaryDto) {

        return tbSummaryService.getDailyMonthList(summaryDto);
    }

    /**
     * 查询所有月报业务列表
     */
//    @GetMapping("/allMonth-summary")
//    public AjaxResult allMonthSummary(TbSummaryDto summaryDto) {
//
//        return tbSummaryService.getAllDailyMonthList(summaryDto);
//    }

    @GetMapping("/allMonth-summary")
    public TableDataInfo allMonthSummary( TbSummaryDto TbSummaryDto, PageDomain pageDomain)
    {
        PageHelper.startPage(pageDomain.getPageNum(),pageDomain.getPageSize());
        List<TbSummary> list = tbSummaryService.getAllDailyMonthList(TbSummaryDto);
        return getDataTable(list);
    }

    /**
     * 查询日报
     * @param tbSummary
     * @return
     */
    @RequestMapping({"day-summary"})
    public AjaxResult daySummary( TbSummaryDto tbSummary) {
        return this.tbSummaryService.searchByDate(tbSummary);
    }

    /**
     * 首页一个月存在日报的列表
     * @return
     */
    @GetMapping("/monthlist")
    public AjaxResult monthlist( TbSummaryDto summaryDto) {

        return tbSummaryService.getListByIdYearMonthType(summaryDto);
    }

    /**
     * 查询周报
     * @param tbSummaryDto
     * @return
     */
    @GetMapping("/weekSummary")
    public AjaxResult weekList (TbSummaryDto tbSummaryDto){
        startPage();
        return tbSummaryService.getWeekListByUserId(tbSummaryDto);
    }

}

